package com.ruoyi.mall.pms.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mall.pms.domain.PmsProductAttributeCategory;
import com.ruoyi.mall.pms.service.IPmsProductAttributeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品类型Controller
 *
 * @author xuxing
 * @date 2021-02-03
 */
@RestController
@RequestMapping("/pms/productAttributeCategory")
public class PmsProductAttributeCategoryController extends BaseController
{
    @Autowired
    private IPmsProductAttributeCategoryService pmsProductAttributeCategoryService;

    /**
     * 查询商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('pms:productAttributeCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsProductAttributeCategory pmsProductAttributeCategory)
    {
        startPage();
        List<PmsProductAttributeCategory> list = pmsProductAttributeCategoryService.selectPmsProductAttributeCategoryList(pmsProductAttributeCategory);
        return getDataTable(list);
    }

    /**
     * 导出商品类型列表
     */
    @PreAuthorize("@ss.hasPermi('pms:productAttributeCategory:export')")
    @Log(title = "商品类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PmsProductAttributeCategory pmsProductAttributeCategory)
    {
        List<PmsProductAttributeCategory> list = pmsProductAttributeCategoryService.selectPmsProductAttributeCategoryList(pmsProductAttributeCategory);
        ExcelUtil<PmsProductAttributeCategory> util = new ExcelUtil<PmsProductAttributeCategory>(PmsProductAttributeCategory.class);
        return util.exportExcel(list, "productAttributeCategory");
    }

    /**
     * 获取商品类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:productAttributeCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pmsProductAttributeCategoryService.selectPmsProductAttributeCategoryById(id));
    }

    /**
     * 新增商品类型
     */
    @PreAuthorize("@ss.hasPermi('pms:productAttributeCategory:add')")
    @Log(title = "商品类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsProductAttributeCategory pmsProductAttributeCategory)
    {
        return toAjax(pmsProductAttributeCategoryService.insertPmsProductAttributeCategory(pmsProductAttributeCategory));
    }

    /**
     * 修改商品类型
     */
    @PreAuthorize("@ss.hasPermi('pms:productAttributeCategory:edit')")
    @Log(title = "商品类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsProductAttributeCategory pmsProductAttributeCategory)
    {
        return toAjax(pmsProductAttributeCategoryService.updatePmsProductAttributeCategory(pmsProductAttributeCategory));
    }

    /**
     * 删除商品类型
     */
    @PreAuthorize("@ss.hasPermi('pms:productAttributeCategory:remove')")
    @Log(title = "商品类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsProductAttributeCategoryService.deletePmsProductAttributeCategoryByIds(ids));
    }
}
